package models

import (
	"time"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

type User struct {
	Id     int
	Name   string
	Passwd string
	Articles []*Article `orm:"reverse(many)"`
}

type Article struct {
	Id int `orm:"pk;auto"`
	ArtiName string `orm:"size(20)"`
	Atime time.Time `orm:"auto_now"` 
	Acount int `orm:"default(0);null"`
	Acontent string    `orm:"size(500)"`
	Aimg string `orm:"size(100)"`
	ArticleType *ArticleType `orm:"rel(fk);on_delete(set_null);null"`
	Users []*User `orm:"rel(m2m)"`
}

type ArticleType struct {
	Id int
	TypeName string `orm:"size(20)"`
	Articles []*Article `orm:"reverse(many)"`
}

func init() {
	orm.RegisterDataBase("default", "mysql", "root:rootroot@tcp(47.111.181.52:3306)/article_manage?charset=utf8")

	orm.RegisterModel(new(User),new(Article),new(ArticleType))
	orm.RunSyncdb("default", false, true)
}
